//
//  STProDetailVC.m
//  YiYueHairdresser
//
//  Created by zhouzhouzhou on 2018/10/12.
//  Copyright © 2018年 YuYiLian. All rights reserved.
//

#import "STProDetailVC.h"
#import "STProDetailView.h"
#import "STShowColListView.h"
#import "STProDetailListView.h"
#import "STProDetailView.h"
#import "STMainPageModel.h"

@interface STProDetailVC ()<STProDetailViewDelegate>{
    NSMutableArray * arrProjects;
    NSDictionary * projectDic;
}
@property(nonatomic, strong) STHairProDetailInfoModel *model;
@property(nonatomic, strong) STProDetailView * detailView;
@end

@implementation STProDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"作品详情";
    
    UIBarButtonItem *rightBarBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(actionShareProject)];
    UIButton * likeBtn =[[UIButton alloc]init];
    [likeBtn setTitle:@"❤️" forState:UIControlStateNormal];
    [likeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    likeBtn.frame=CGRectMake(0, 0, 30, 30);
    [likeBtn addTarget:self action:@selector(actionLikeProject) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * likeBarBtn = [[UIBarButtonItem alloc]initWithCustomView:likeBtn];
    
    self.navigationItem.rightBarButtonItems =@[rightBarBtn,likeBarBtn];
    
    self.view.backgroundColor = [UIColor blackColor];
    [self loadProjectData];
    [self proImageScrollView];
//    [self loadProjectScrollView];
//    [self loadFooterView];
    [self getProDetailDataFromeService];
}

#pragma mark - 网络请求
- (void)getProDetailDataFromeService {
    if(self.projectId.length > 0){
    BasicRequest * request = [[BasicRequest alloc] initWithParams:@{@"opusId":self.projectId}];
    request.URL = [NSString stringWithFormat:@"%@%@",SWBaseUrlA, @"stylistOpus/getStylgetStylistOpusByOpusId"];
    request.requestMethod = HttpRequestMethodGET;
    [request startRequestWithSuccess:^(NSURLSessionTask *task, id responseObject) {
        NSNumber *code = responseObject[@"code"];
        NSDictionary *dict = responseObject[@"data"];
        if (code.integerValue == 200) {
        
            if(![dict isKindOfClass:[NSNull class]]){
            
                NSNumber *collection = dict[@"collection"];
                NSNumber *proId = dict[@"id"];
                NSNumber *pageview = dict[@"pageview"];
                NSNumber *reposted = dict[@"reposted"];
                NSArray *opusPaths = dict[@"opusPaths"];
                NSString *describe = dict[@"describe"];
                
            _model = [STHairProDetailInfoModel new];
            _model.collection =collection.intValue;
                _model.opusId = proId.longValue;
                _model.pageview = pageview.intValue;
                _model.reposted = reposted.intValue;
                _model.pictrue = opusPaths;
                _model.describe = describe;
                [_detailView setProDetailViewWithDicData:_model];
            }
            
            
            
        }
    } Failure:nil];
    } else {
       [_detailView setProDetailViewWithDicData:projectDic];
    }
}


//分享作品
- (void)actionShareProject {
   
}
- (void)actionLikeProject {
    
}

- (void)loadProjectData{
    projectDic =@{@"num":@8,@"name":@""};
}

-(void)proImageScrollView{
    STProDetailView * detailView = [[STProDetailView alloc]initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
    detailView.delegate = self;
    //[detailView setProDetailViewWithDicData:projectDic];
    [self.view addSubview:detailView];
    _detailView = detailView;
}


-(void)proDetailViewImgSelNum:(NSInteger)row{
    NSLog(@"选择了%d",(int)row);
}





///////
- (void)loadProjectScrollView{
    NSMutableArray * arrTopBars = [NSMutableArray arrayWithCapacity:arrProjects.count];
    for (NSDictionary * dicPro in arrProjects) {
        [arrTopBars addObject:dicPro[@"name"]];
    }
    
    STProDetailListView * imgDetailView = [[STProDetailListView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64-60)];
    //imgDetailView.delegate = self;
    [imgDetailView setProDetailImgListViewWithArr:arrProjects];
    [self.view addSubview:imgDetailView];
 
}



-(void)loadFooterView{
    UILabel * nextLab = [[UILabel alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT-64-60, SCREEN_WIDTH, 60)];
    nextLab.backgroundColor = [UIColor clearColor];
    nextLab.textColor = [UIColor whiteColor];
    nextLab.textAlignment = NSTextAlignmentCenter;
    nextLab.font = FONT(13);
    nextLab.text = @"上划查看下一作品↓";
    [self.view addSubview:nextLab];
}


-(void)proDetailListViewProImgScrollToNum:(NSInteger)row{
    
}



@end
